//
//  LBEffect4Filter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 11/22/12.
//  Copyright (c) 2012 UIT. All rights reserved.
//

#include <iostream>
#include "LBEffect4Filter.h"

char fShaderStrEffect4[] = ""
"precision highp float;  "
"varying highp vec2 vtexCoor; "
"uniform sampler2D texture; "

"float safeColorF(float color){"
"    if(color > 1.0) color = 1.0;"
"    else if(color < 0.0) color = 0.0;"
"    return color;"
"}"

"vec4 safeColor(vec4 color){"
"    color.r = safeColorF(color.r);"
"    color.g = safeColorF(color.g);"
"    color.b = safeColorF(color.b);"
"    return color;"
"}"

//grey scale function
"vec4 greyscaleColor(vec4 color){"
"float greyColor = color.r*0.3 + color.g*0.59 + color.b*0.11;"
"color = vec4(greyColor, greyColor, greyColor, 1.0);"
"color = safeColor(color);"
"return color;"
"}"
//END grey scale function

//tin effect function
"vec4 tintEffect(vec4 color, float rMax, float gMax, float bMax, float rMin, float gMin, float bMin){"
"color.r = (color.r - rMin)*(1.0/(rMax - rMin));"
"color.g = (color.g - gMin)*(1.0/(gMax - gMin));"
"color.b = (color.b - bMin)*(1.0/(bMax - bMin));"
"color = safeColor(color);"
"return color;"
"}"
//END tin effect function


"void main() "
"{ "
"     vec4 textureColor = texture2D(texture, vtexCoor); "

"textureColor = greyscaleColor(textureColor);"
"textureColor = tintEffect(textureColor, 0.667, 0.667, 0.902, 0.235, 0.137, 0.039);"

"    gl_FragColor = textureColor; "
"} ";

LBEffect4Filter::LBEffect4Filter(){
    init(0, fShaderStrEffect4);
}